package cn.ruituo.test;

import cn.ruituo.dao.StudentDao;
import cn.ruituo.entity.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

/**
 * @author oldliu
 * @since 1.0
 */
public class StudentDaoTest3 {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //connection
        SqlSession session = sqlSessionFactory.openSession();
        StudentDao dao=session.getMapper(StudentDao.class);
        Student student = new Student();
        student.setSname("小胡");
        student.setQq("393934454");
        student.setGradeid(5);
        int r=dao.add(student);
        System.out.println("增加了:"+r+"条");
        session.commit();
        session.close();
    }
}
